#include <CL/cl.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>

int main() {
   cl_platform_id platform;
   cl_device_id dev;
   int err;
   char        *value;
   size_t      valueSize;
   size_t      maxWorkItemPerGroup;
   cl_uint     maxComputeUnits=0;
   cl_ulong    maxGlobalMemSize=0;
   cl_ulong    maxConstantBufferSize=0;
   cl_ulong    maxLocalMemSize=0;

   /* Identify a platform */
   err = clGetPlatformIDs(1, &platform, NULL);
   if(err < 0) {
      perror("Couldn't identify a platform");
      return -1;
   } 

   /* Access a device */
   err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &dev, NULL);


   ///print the device name
   clGetDeviceInfo(dev, CL_DEVICE_NAME, 0, NULL, &valueSize);
   value = (char*) malloc(valueSize);
   clGetDeviceInfo(dev, CL_DEVICE_NAME, valueSize, value, NULL);
   printf("Device Name: %s\n", value);
   free(value);

   /// print parallel compute units(CU)
   clGetDeviceInfo(dev, CL_DEVICE_MAX_COMPUTE_UNITS,sizeof(maxComputeUnits), &maxComputeUnits, NULL);
   printf("Parallel compute units: %u\n", maxComputeUnits);

   ///maxWorkItemPerGroup
   clGetDeviceInfo(dev, CL_DEVICE_MAX_WORK_GROUP_SIZE,sizeof(maxWorkItemPerGroup), &maxWorkItemPerGroup, NULL);
   printf("maxWorkItemPerGroup: %zd\n", maxWorkItemPerGroup);

   /// print maxGlobalMemSize
   clGetDeviceInfo(dev, CL_DEVICE_GLOBAL_MEM_SIZE,sizeof(maxGlobalMemSize), &maxGlobalMemSize, NULL);
   printf("maxGlobalMemSize: %lu(MB)\n", maxGlobalMemSize/1024/1024);

   /// print maxConstantBufferSize
   clGetDeviceInfo(dev, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE,sizeof(maxConstantBufferSize), &maxConstantBufferSize, NULL);
   printf("maxConstantBufferSize: %lu(KB)\n", maxConstantBufferSize/1024);

   /// print maxLocalMemSize
   clGetDeviceInfo(dev, CL_DEVICE_LOCAL_MEM_SIZE,sizeof(maxLocalMemSize), &maxLocalMemSize, NULL);
   printf("maxLocalMemSize: %lu(KB)\n", maxLocalMemSize/1024);

   size_t size;
   clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
   clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, value, NULL);
   printf("OpenCL version: %s\n", value);
   return 0;
}